import csrsa
import configurator

def firmar(text,e,n):
	validateWord = configurator.GetConfig().get('RSA', 'validateWord')
	return csrsa.encriptaTexto(validateWord + text, e, n)
	
def desfirmar(text,d,n):
	decryptedText = csrsa.desencriptaNumero(text,d,n)
	validateWord = configurator.GetConfig().get('RSA', 'validateWord')
	if validarEncriptacion(decryptedText):
		return decryptedText[len(validateWord):]
	else:
                return "error"

def validarEncriptacion(text):
    valText=configurator.GetConfig().get('RSA', 'validateWord')
    return len(text) > len(valText) and text[:len(valText)] == valText
